package win.smartown.kotlin.grammar

/**
 * Created by smartown on 2017/6/4.
 * 循环
 */
fun main(args: Array<String>) {
    printList1()
    printList2()
    printList3()
}

fun printList1() {
    val items = listOf("apple", "banana", "perl")
    println("for1:")
    for (item in items) {
        println(item)
    }
}

fun printList2() {
    val items = listOf("apple", "banana", "perl")
    println("for2:")
    for (index in items.indices) {
        println("item at $index is ${items[index]}")
    }
}

fun printList3() {
    val items = listOf("apple", "banana", "perl")
    var index = 0
    println("while:")
    while (index < items.size) {
        println("item at $index is ${items[index]}")
        index++
    }
}